// 市场概览页面 Mock 数据

// 市场总体统计数据
export interface MarketStats {
  totalMarketCap: number
  totalMarketCapChange24h: number
  totalVolume24h: number
  totalVolumeChange24h: number
  btcDominance: number
  btcDominanceChange24h: number
  ethDominance: number
  ethDominanceChange24h: number
  activeCryptocurrencies: number
  totalExchanges: number
  fearGreedIndex: number
  fearGreedLevel: string
}

// 热门币种数据
export interface HotCoin {
  id: string
  symbol: string
  name: string
  image: string
  currentPrice: number
  priceChange24h: number
  priceChangePercentage24h: number
  marketCap: number
  marketCapRank: number
  volume24h: number
  volumeChange24h: number
  circulatingSupply: number
  totalSupply: number
  maxSupply: number | null
  ath: number
  athChangePercentage: number
  athDate: string
  atl: number
  atlChangePercentage: number
  atlDate: string
  sparklineIn7d: number[]
  lastUpdated: string
}

// 市场热点分类
export interface MarketCategory {
  id: string
  name: string
  marketCap: number
  marketCapChange24h: number
  volume24h: number
  volumeChange24h: number
  topCoins: string[]
}

// 恐慌贪婪指数历史数据
export interface FearGreedHistory {
  value: number
  valueClassification: string
  timestamp: string
  timeUntilUpdate: string
}

// Mock 数据
export const mockMarketStats: MarketStats = {
  totalMarketCap: 2456789123456,
  totalMarketCapChange24h: 2.34,
  totalVolume24h: 89765432109,
  totalVolumeChange24h: -1.23,
  btcDominance: 52.3,
  btcDominanceChange24h: 0.15,
  ethDominance: 17.8,
  ethDominanceChange24h: -0.32,
  activeCryptocurrencies: 13847,
  totalExchanges: 685,
  fearGreedIndex: 73,
  fearGreedLevel: 'Greed'
}

export const mockHotCoins: HotCoin[] = [
  {
    id: 'bitcoin',
    symbol: 'BTC',
    name: 'Bitcoin',
    image: 'https://assets.coingecko.com/coins/images/1/large/bitcoin.png',
    currentPrice: 67234.56,
    priceChange24h: 1234.78,
    priceChangePercentage24h: 1.87,
    marketCap: 1324567890123,
    marketCapRank: 1,
    volume24h: 23456789012,
    volumeChange24h: 5.67,
    circulatingSupply: 19687234,
    totalSupply: 19687234,
    maxSupply: 21000000,
    ath: 73738.23,
    athChangePercentage: -8.82,
    athDate: '2024-03-14T07:10:36.635Z',
    atl: 67.81,
    atlChangePercentage: 99089.45,
    atlDate: '2013-07-06T00:00:00.000Z',
    sparklineIn7d: [66234, 66789, 67123, 66456, 67890, 68234, 67234],
    lastUpdated: new Date().toISOString()
  },
  {
    id: 'ethereum',
    symbol: 'ETH',
    name: 'Ethereum',
    image: 'https://assets.coingecko.com/coins/images/279/large/ethereum.png',
    currentPrice: 3456.78,
    priceChange24h: -89.23,
    priceChangePercentage24h: -2.52,
    marketCap: 415678901234,
    marketCapRank: 2,
    volume24h: 12345678901,
    volumeChange24h: -3.45,
    circulatingSupply: 120234567,
    totalSupply: 120234567,
    maxSupply: null,
    ath: 4878.26,
    athChangePercentage: -29.14,
    athDate: '2021-11-10T14:24:19.604Z',
    atl: 0.432979,
    atlChangePercentage: 798345.67,
    atlDate: '2015-10-20T00:00:00.000Z',
    sparklineIn7d: [3567, 3445, 3389, 3456, 3523, 3489, 3456],
    lastUpdated: new Date().toISOString()
  },
  {
    id: 'binancecoin',
    symbol: 'BNB',
    name: 'BNB',
    image: 'https://assets.coingecko.com/coins/images/825/large/bnb-icon2_2x.png',
    currentPrice: 589.34,
    priceChange24h: 23.45,
    priceChangePercentage24h: 4.14,
    marketCap: 85678901234,
    marketCapRank: 3,
    volume24h: 1234567890,
    volumeChange24h: 12.34,
    circulatingSupply: 145456789,
    totalSupply: 145456789,
    maxSupply: 200000000,
    ath: 686.31,
    athChangePercentage: -14.13,
    athDate: '2021-05-10T07:24:17.097Z',
    atl: 0.0398177,
    atlChangePercentage: 1479567.89,
    atlDate: '2017-10-19T00:00:00.000Z',
    sparklineIn7d: [567, 578, 589, 595, 601, 594, 589],
    lastUpdated: new Date().toISOString()
  },
  {
    id: 'solana',
    symbol: 'SOL',
    name: 'Solana',
    image: 'https://assets.coingecko.com/coins/images/4128/large/solana.png',
    currentPrice: 189.67,
    priceChange24h: 8.92,
    priceChangePercentage24h: 4.93,
    marketCap: 89123456789,
    marketCapRank: 4,
    volume24h: 2345678901,
    volumeChange24h: 18.76,
    circulatingSupply: 469876543,
    totalSupply: 580123456,
    maxSupply: null,
    ath: 259.96,
    athChangePercentage: -27.05,
    athDate: '2021-11-06T21:54:35.825Z',
    atl: 0.500801,
    atlChangePercentage: 37767.89,
    atlDate: '2020-05-11T19:35:23.449Z',
    sparklineIn7d: [178, 182, 185, 189, 194, 191, 189],
    lastUpdated: new Date().toISOString()
  },
  {
    id: 'cardano',
    symbol: 'ADA',
    name: 'Cardano',
    image: 'https://assets.coingecko.com/coins/images/975/large/cardano.png',
    currentPrice: 0.456789,
    priceChange24h: -0.012345,
    priceChangePercentage24h: -2.63,
    marketCap: 16234567890,
    marketCapRank: 8,
    volume24h: 345678901,
    volumeChange24h: -5.67,
    circulatingSupply: 35567890123,
    totalSupply: 45000000000,
    maxSupply: 45000000000,
    ath: 3.09,
    athChangePercentage: -85.21,
    athDate: '2021-09-02T06:00:10.474Z',
    atl: 0.01925275,
    atlChangePercentage: 2272.34,
    atlDate: '2020-03-13T02:22:55.391Z',
    sparklineIn7d: [0.467, 0.459, 0.452, 0.456, 0.461, 0.458, 0.456],
    lastUpdated: new Date().toISOString()
  }
]

export const mockMarketCategories: MarketCategory[] = [
  {
    id: 'layer-1',
    name: 'Layer 1',
    marketCap: 1567890123456,
    marketCapChange24h: 2.45,
    volume24h: 23456789012,
    volumeChange24h: 1.23,
    topCoins: ['bitcoin', 'ethereum', 'solana', 'cardano']
  },
  {
    id: 'defi',
    name: 'DeFi',
    marketCap: 234567890123,
    marketCapChange24h: -1.56,
    volume24h: 5678901234,
    volumeChange24h: -2.34,
    topCoins: ['uniswap', 'chainlink', 'aave', 'compound']
  },
  {
    id: 'nft',
    name: 'NFT',
    marketCap: 45678901234,
    marketCapChange24h: 5.67,
    volume24h: 1234567890,
    volumeChange24h: 8.91,
    topCoins: ['enjincoin', 'theta', 'chiliz', 'flow']
  },
  {
    id: 'gaming',
    name: 'Gaming',
    marketCap: 23456789012,
    marketCapChange24h: 3.45,
    volume24h: 567890123,
    volumeChange24h: 4.56,
    topCoins: ['axie-infinity', 'the-sandbox', 'decentraland', 'gala']
  },
  {
    id: 'metaverse',
    name: 'Metaverse',
    marketCap: 34567890123,
    marketCapChange24h: 7.89,
    volume24h: 789012345,
    volumeChange24h: 12.34,
    topCoins: ['the-sandbox', 'decentraland', 'enjincoin', 'mana']
  }
]

export const mockFearGreedHistory: FearGreedHistory[] = [
  {
    value: 73,
    valueClassification: 'Greed',
    timestamp: new Date().toISOString(),
    timeUntilUpdate: '12 hours'
  },
  {
    value: 68,
    valueClassification: 'Greed',
    timestamp: new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString(),
    timeUntilUpdate: '12 hours'
  },
  {
    value: 65,
    valueClassification: 'Greed',
    timestamp: new Date(Date.now() - 2 * 24 * 60 * 60 * 1000).toISOString(),
    timeUntilUpdate: '12 hours'
  },
  {
    value: 58,
    valueClassification: 'Neutral',
    timestamp: new Date(Date.now() - 3 * 24 * 60 * 60 * 1000).toISOString(),
    timeUntilUpdate: '12 hours'
  },
  {
    value: 52,
    valueClassification: 'Neutral',
    timestamp: new Date(Date.now() - 4 * 24 * 60 * 60 * 1000).toISOString(),
    timeUntilUpdate: '12 hours'
  },
  {
    value: 45,
    valueClassification: 'Fear',
    timestamp: new Date(Date.now() - 5 * 24 * 60 * 60 * 1000).toISOString(),
    timeUntilUpdate: '12 hours'
  },
  {
    value: 41,
    valueClassification: 'Fear',
    timestamp: new Date(Date.now() - 6 * 24 * 60 * 60 * 1000).toISOString(),
    timeUntilUpdate: '12 hours'
  }
]

// 模拟API获取数据的函数
export const fetchMarketStats = async (): Promise<MarketStats> => {
  // 模拟API延迟
  await new Promise(resolve => setTimeout(resolve, 500))
  return mockMarketStats
}

export const fetchHotCoins = async (limit: number = 20): Promise<HotCoin[]> => {
  // 模拟API延迟
  await new Promise(resolve => setTimeout(resolve, 800))
  return mockHotCoins.slice(0, limit)
}

export const fetchMarketCategories = async (): Promise<MarketCategory[]> => {
  // 模拟API延迟
  await new Promise(resolve => setTimeout(resolve, 600))
  return mockMarketCategories
}

export const fetchFearGreedHistory = async (days: number = 7): Promise<FearGreedHistory[]> => {
  // 模拟API延迟
  await new Promise(resolve => setTimeout(resolve, 400))
  return mockFearGreedHistory.slice(0, days)
}

// 格式化数字的工具函数
export const formatNumber = (num: number, decimals: number = 2): string => {
  if (num >= 1e12) {
    return (num / 1e12).toFixed(decimals) + 'T'
  } else if (num >= 1e9) {
    return (num / 1e9).toFixed(decimals) + 'B'
  } else if (num >= 1e6) {
    return (num / 1e6).toFixed(decimals) + 'M'
  } else if (num >= 1e3) {
    return (num / 1e3).toFixed(decimals) + 'K'
  }
  return num.toFixed(decimals)
}

// 格式化价格的工具函数
export const formatPrice = (price: number): string => {
  if (price >= 1) {
    return '$' + price.toLocaleString('en-US', {
      minimumFractionDigits: 2,
      maximumFractionDigits: 2
    })
  } else {
    return '$' + price.toFixed(6)
  }
}

// 格式化百分比的工具函数
export const formatPercentage = (percentage: number): string => {
  const sign = percentage >= 0 ? '+' : ''
  return sign + percentage.toFixed(2) + '%'
} 